package com.study.agp.twowaybinding;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import android.view.View;
import com.study.agp.R;
import com.study.agp.databinding.ActivityTwoWayBinding;

public class TwoWayActivity extends AppCompatActivity {
    private TWDBook book = new TWDBook();
    private TWDBook2 book2 = new TWDBook2();
    private ActivityTwoWayBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_two_way);
        resetBook();
        binding.setTwoWayBook(book);

        resetBook2();
        binding.setTwoWayBook2(book2);
    }

    public void onResetBook(View view) {
        resetBook();
    }

    public void onResetBook2(View view) {
        resetBook2();
    }

    private void resetBook() {
        book.setTitle("第一行代码");
        book.setAuthor("郭霖");
        book.setPrice("100");
    }

    private void resetBook2() {
        book2.getPrice().set("101");
    }
}